import { getOrders } from '@/api/order'

const state = {
  orderList: [],
  total: 0
}

const mutations = {
  CHANGE_ORDERLIST(state, orderList) {
    state.orderList = orderList
  },
  CHANGE_TOTAL(state, total) {
    state.total = total
  }
}

const actions = {
  async changeOrderList ({commit}, queryInfo) {
    const data = await getOrders(queryInfo)
    if (data.meta.status !== 200) {
      return this.$message.error('获取订单列表失败！')
    }
    commit('CHANGE_ORDERLIST', data.data.goods)
    commit('CHANGE_TOTAL', data.data.total)
  }
}

export default {
  state,
  actions,
  mutations
}
